package com.acme.bankapp.domain.bank;

import java.io.Serializable;

import com.acme.bankapp.domain.exceptions.OverDraftLimitExceededException;

public class CheckingAccount extends AbstractAccount implements Serializable {

	private double overdraft;
	
	public CheckingAccount(final double amount, final int id, final double overdraft) {
		super(amount, id);
		this.overdraft = overdraft;
	}
	
	public CheckingAccount(final double amount, final double overdraft) {
		super(amount);
		this.overdraft = overdraft;
	}
	
	public CheckingAccount(final int id) {
		super(id);		
	}
	
	public CheckingAccount() { 
		this(0, 0, 1000);
	}
			
	@Override
	public String toString() {
		return "CheckingAccount #" + id + ", the balance is " + balance
				+ ", the maximum credit amount is " + overdraft;
	}

	public double maximumAmountToWithdraw() {
		return this.balance + overdraft;
	}
		
	public void withdraw(final double amount) throws IllegalArgumentException, OverDraftLimitExceededException {		
		
		if(amount < 0)
		{
			throw new IllegalArgumentException("the wrong amount");
		}
		
	   if ((this.balance + overdraft) < amount) {
		   double exceed = -(this.balance + overdraft - amount);
			throw new OverDraftLimitExceededException("request exceeds the limit on " + exceed, exceed);
		}
		this.balance -= amount;	
				
	}

}
